package nix.demo8.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import nix.demo8.domain.City;
import nix.demo8.service.Service;

public class CityServlet extends HttpServlet {

	private Service service = new Service();

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");

		int pid = Integer.parseInt(request.getParameter("pid"));
		List<City> cityList = service.findByProvince(pid);
		String json = JSONArray.fromObject(cityList).toString();
		response.getWriter().print(json);
	}

}
